package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class HJ27_异常的打卡记录 {
  public static void main(String[] args) throws FileNotFoundException {
    Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/27.txt"));
    int N = in.nextInt();
    List<Node> list = new ArrayList<>();
    in.nextLine(); // 因为上一次是 nextInt()，而下一次是 nextLine()，所以用 nextLine() 吸收换行
    for (int i = 0; i < N; i++) {
      String[] sArray = in.nextLine().split(",");
      Node tmp =
          new Node(
              Integer.parseInt(sArray[0]),
              Integer.parseInt(sArray[1]),
              Integer.parseInt(sArray[2]),
              sArray[3],
              sArray[4]);
      tmp.isError = tmp.doCheck();
      list.add(tmp);
    }
    boolean flag = false;
    for (int i = 0; i < N; i++) {
      Node now = list.get(i);
      if (i == 0) {
        if (now.isError) {
          System.out.print(now.toString());
        }
      } else {
        Node before = list.get(i - 1);
        if (now.id == before.id) {
          int t = now.time - before.time;
          int d = now.distance - before.distance;
          if (t < 60 && d > 5) {
            if (before.isError) {
              if (!flag) {
                System.out.print(now.toString());
                flag = true;
              } else {
                System.out.print(";" + now.toString());
              }
            } else {
              if (!flag) {
                System.out.print(before.toString() + ";" + now.toString());
                flag = true;
              } else {
                System.out.print(";" + before.toString() + ";" + now.toString());
              }
            }
            continue;
          }
        }
        if (now.isError) {
          if (!flag) {
            System.out.print(now.toString());
            flag = true;
          } else {
            System.out.print(";" + now.toString());
          }
        }
      }
    }
    if (!flag) {
      System.out.print("null");
    }
  }

  static class Node {
    int id;
    int time;
    int distance;
    String actualDevice;
    String registeredDevice;
    boolean isError;

    @Override
    public String toString() {
      return id + "," + time + "," + distance + "," + actualDevice + "," + registeredDevice;
    }

    public Node(int id, int time, int distance, String actualDevice, String registeredDevice) {
      this.id = id;
      this.time = time;
      this.distance = distance;
      this.actualDevice = actualDevice;
      this.registeredDevice = registeredDevice;
    }

    public boolean doCheck() {
      return this.isError = !this.actualDevice.equals(this.registeredDevice);
    }
  }
}
